﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
namespace SQT.tracnghiem
{
    public partial class Personal : System.Web.UI.Page
    {
        public int? user, sex=1, old=0, city, province,day,month,year, get_year = DateTime.Now.Year-5;
        public string banner,avatar,fullname, email, address="", phone="";
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                user = int.Parse(RouteData.Values["id"].ToString());
                var find_user = new TblUserController().FetchAll().Where(x => x.UserId == user).ToList();
                if (find_user.Count == 0 || user==0)
                {
                    Response.Redirect("~/trang-chu");
                }
                else
                {
                    banner = find_user[0].Wallpaper;
                    avatar = find_user[0].Avatar;
                    fullname = find_user[0].FullName;
                    email = find_user[0].Email;
                    if (find_user[0].Sex == false)
                        sex = 0;
                    old = DateTime.Now.Year - DateTime.Parse(find_user[0].BirthDay.ToString()).Year;

                    if (find_user[0].Address != null)
                    {
                        var get_city = new TblCityController().FetchAll().Where(x => x.Id == find_user[0].Address).Single();
                        var get_province = new TblProvinceController().FetchAll().Where(x => x.Id == get_city.ProvinceId).Single();
                        address += get_city.CityName + " - " + get_province.ProvinceName;
                        city = int.Parse(find_user[0].Address.ToString());
                        province = int.Parse(get_province.Id.ToString());
                    }

                    day = DateTime.Parse(find_user[0].BirthDay.ToString()).Day;
                    month = DateTime.Parse(find_user[0].BirthDay.ToString()).Month;
                    year = DateTime.Parse(find_user[0].BirthDay.ToString()).Year;
                    phone = find_user[0].Phone;

                    city = find_user[0].Address;

                }
            }
            catch
            {
                Response.Redirect("~/trang-chu");
            }
        }
    }
}